/**
 * Uri编码解码工具类
 */
export default class UriUtil {
    /**
     * 编码
     * @param content 
     * @returns 
     */
    static encode(content: any): string {
        if (typeof content == "object") {
            return encodeURIComponent(JSON.stringify(content).replace(/%/g, '%25'));
        } else {
            return encodeURIComponent(content.replace(/%/g, '%25'));
        }
    }
    /**
     * 解码
     * @param content
     * @returns
     */
    static decode<T>(content: string): T {
        let data = decodeURIComponent(content);
        // 使用条件类型检查，如果T是string类型，则直接返回，否则进行JSON解析
        return (typeof data === 'string' && {} as T instanceof String)
            ? data as unknown as T
            : JSON.parse(data) as T;
    }
}